package cn.lg.soar.mvc.converter;

import cn.lg.soar.common.data.dict.IDict;
import cn.lg.soar.common.util.EnumUtils;
import org.springframework.core.convert.converter.Converter;

/**
 * 枚举转换器
 * @author luguoxiang
 * @date 2022/8/25
 * 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
 */
public class IDictConverter<T extends IDict> implements Converter<String, T> {

    private final Class<T> targetType;

    public IDictConverter(Class<T> targetType) {
        this.targetType = targetType;
    }

    @Override
    public T convert(String source) {
        return EnumUtils.valueOf(targetType, source);
    }

}